<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="fragments/easyui_insdep_head :: easyui_insdep_head" th:with="title='仓库管理'">
</head>
<body>

<table id="tt" class="easyui-datagrid" style="width:100%;height:100%"
       url="/repertory/list" toolbar="#tb" pageList='[1,10,20,30,50]' singleSelect="true" method="get"
       rownumbers="true" pagination="true">
    <thead>
    <tr>
        <th field="repertoryId" width="80">仓库ID</th>
        <th field="repertoryName" width="80">仓库名称</th>
        <th field="repertoryLoc" width="160">仓库地址</th>
        <th field="repertoryNote" width="160">备注</th>
    </tr>
    </thead>
</table>

<div id="tb" style="padding:3px">
    <span>仓库ID:</span>
    <input id="repertoryId" style="line-height:26px;border:1px solid #ccc"/>
    <span>仓库名称:</span>
    <input id="repertoryName" style="line-height:26px;border:1px solid #ccc"/>
    <span>仓库地址:</span>
    <input id="repertoryLoc" style="line-height:26px;border:1px solid #ccc"/>
    <input type="checkbox" id="isFuzzy" checked="checked"/>模糊查询
    <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">查找</a>
    <a href="#" class="easyui-linkbutton" plain="true" onclick="doReSet()">重置</a>
    <script type="text/javascript">
        //<![CDATA[
        function doSearch() {
            param = {};
            if ($('#repertoryId').val())
                param.repertoryId = $('#repertoryId').val();
            if ($('#repertoryName').val())
                param.repertoryName = $('#repertoryName').val();
            if ($('#repertoryLoc').val())
                param.repertoryLoc = $('#repertoryLoc').val();
            param.isFuzzy = $('#isFuzzy').is(':checked');

            $('#tt').datagrid('load', param);
        }
        function doReSet() {
            $('#repertoryId').val("");
            $('#repertoryName').val("");
            $('#repertoryLoc').val("");
            if (!$('#isFuzzy').is(':checked')) {
                $('#isFuzzy').click();
            }
            doSearch();
        }
        //]]>
    </script>
</div>

<div id="ajaxWin" class="easyui-window" title=""
     data-options="modal:true,collapsible:true,closed:true,maximizable:false,minimizable:false,resizable:false"
     style="width:600px;height:500px;overflow: hidden">
    <iframe id="frame" name="frame" frameborder="0" style="height:100%;width:100%; "/>
</div>

<!--用于iframe post值的隐藏表单-->
<form target="frame" id="iframepostfrom">
    <input type="hidden" name="repertoryId" id="ffRepertoryId"/>
    <input type="hidden" name="repertoryName" id="ffRepertoryName"/>
    <input type="hidden" name="repertoryLoc" id="ffRepertoryLoc"/>
    <input type="hidden" name="repertoryNote" id="ffRepertoryNote"/>
</form>


<script type="text/javascript">
    //<![CDATA[
    $(function () {
        $('#ajaxWin').window({
            onBeforeClose: function () { //当面板关闭之前触发的事件
                $("#tt").datagrid("reload");
            }
        });

        var pager = $('#tt').datagrid().datagrid('getPager');	// get the pager of datagrid
        pager.pagination({
            buttons: [{
                iconCls: 'icon-add',
                handler: function () {
                    windowOpen("增加仓库", "/repertory/pages/repertoryAddPage");
                }
            }, {
                iconCls: 'icon-edit',
                handler: function () {
                    row = $("#tt").datagrid('getSelected');

                    if (row == null) {
                        $.messager.alert('警告', '请选中需要修改的仓库', 'info');
                        return;
                    }

                    windowOpen("修改仓库信息", "/repertory/pages/repertoryUpdatePage", row);
                }
            }, {
                iconCls: 'icon-remove',
                handler: function () {
                    row = $("#tt").datagrid('getSelected');

                    if (row == null) {
                        $.messager.alert('警告', '请选中需要删除的仓库', 'info');
                        return;
                    }

                    $.messager.confirm('警告', '确定删除该仓库吗', function (r) {
                        if (r) {
                            $.ajax({
                                url: "/repertory/" + row.repertoryId,
                                type: "DELETE",
                                success: function (data) {
                                    var data = data == "success" ? "删除成功" : "删除失败";
                                    $.messager.alert('结果', data, 'info');
                                    $("#tt").datagrid("reload");
                                }
                            });
                        }
                    });
                }
            }]
        });


    });

    function windowOpen(title, ajax_url, row) {
        $('#ajaxWin').panel({title: title});

        $("#iframepostfrom").attr("action", ajax_url);
        if (row != null) {
            $('#ffRepertoryId').val(row.repertoryId);
            $('#ffRepertoryName').val(row.repertoryName);
            $('#ffRepertoryLoc').val(row.repertoryLoc);
            $('#ffRepertoryNote').val(row.repertoryNote);
        }

        $('#ajaxWin').window('open');
        $("#iframepostfrom").submit();
    }

    //]]>
</script>


</body>
</html>